#pragma once

#include <iostream>
#include <string>
#include <fstream>

class Util
{
public:
    static std::string getOneline(std::string buffer, const std::string sep)
    {
        auto pos = buffer.find(sep);
        if (pos == std::string::npos)
            return "";
        std::string line = buffer.substr(0, pos);
        buffer.erase(0, line.size() + sep.size());
        return line;
    }
    static bool readFile(const std::string &rsc, std::string *out)
    {
        out->clear();
        std::ifstream in(rsc);
        if (!in.is_open())
            return false;
        std::string line;
        while (std::getline(in, line))
        {
            *out += line;
        }
        in.close();
        return true;
    }
    static void ToSuffix(const std::string& suffix, std::string *rsphead)
    {
        *rsphead = "Content-Type: ";
        if (suffix == ".html") *rsphead += "text/html\r\n";
        else if (suffix == ".jpg") *rsphead += "application/x-jpg\r\n";
    }
};